<include file="public/layout" />
<body style="background-color: rgb(255, 255, 255); overflow: auto; cursor: default; -moz-user-select: inherit;">
<div id="append_parent"></div>
<div id="ajaxwaitid"></div>
<div class="page">
    <div class="fixed-bar">
        <div class="item-title">
            <div class="subject">
                <h3>微信用户管理</h3>
                <h5>网站系统会员索引与管理</h5>
            </div>
        </div>

    </div>
    <!-- 操作说明 -->
    <div id="explanation" class="explanation" style="color: rgb(44, 188, 163); background-color: rgb(237, 251, 248); width: 99%; height: 100%;">
        <div id="checkZoom" class="title"><i class="fa fa-lightbulb-o"></i>
            <h4 title="提示相关设置操作时应注意的要点">操作提示</h4>
            <span title="收起提示" id="explanationZoom" style="display: block;"></span>
        </div>
        <ul>
            <li>微信用户列表管理.</li>
            <li></li>
        </ul>

    </div>
    <div class="flexigrid">
        <div class="mDiv">
            <div class="ftitle">
                <h3>微信用户列表</h3>
                <h5>(共<span id="user_count"></span>条记录)</h5>
            </div>
            <div title="刷新数据" class="pReload"><i class="fa fa-refresh"></i></div>
            <form class="navbar-form form-inline"  id="search-form2" onsubmit="return false">
                <input type="hidden" name="order_by" value="id">
                <input type="hidden" name="sort" value="desc">
                <input type="hidden" name="keywords" id="keywords">
                <div class="sDiv">
                        <input type="text" id="search_key" size="30" class="qsbox" placeholder="用户名">
                        <input type="submit" class="btn" onclick="ajax_get_table('search-form2',1)" value="搜索">
                  </div>
            </form>
        </div>
        <div class="hDiv">
            <div class="hDivBox">
                <table cellspacing="0" cellpadding="0">
                    <thead>
                    <tr>
                        <th class="sign" axis="col0">
                            <div style="width: 24px;"><i class="ico-check"></i></div>
                        </th>
                        <th align="left" abbr="id" axis="col3" class="">
                            <div style="text-align: center; width: 40px;" class="">ID</div>
                        </th>
                        <th align="left" abbr="username" axis="col4" class="">
                            <div style="text-align: center; width: 250px;" class="">用户名</div>
                        </th>
                        <th align="center" abbr="" axis="col6" class="">
                            <div style="text-align: center; width: 220px;" class="">地址</div>
                        </th>
                        <th align="center" abbr="" axis="col6" class="">
                            <div style="text-align: center; width: 120px;" class="">中奖时间</div>
                        </th>
                        <th align="center" abbr="add_time" axis="col6" class="">
                            <div style="text-align: center; width: 180px;" class="">填写资料时间</div>
                        </th>
                        <th align="center" axis="col1" class="handle">
                            <div style="text-align: center; width: 150px;">操作</div>
                        </th>
                        <th style="width:100%" axis="col7">
                            <div></div>
                        </th>
                    </tr>
                    </thead>
                </table>
            </div>
        </div>
        <div class="tDiv">
            <div class="tDiv2">
                <div class="fbutton">
                    <a href="javascript:;" onclick="delAll_user()">
                        <div class="add" title="清空用户记录">
                            <span>清空用户记录</span>
                        </div>
                    </a>
                </div>
                <div class="fbutton">
                    <a href="{:U('Users/export_user')}" >
                        <div class="add" title="导出">
                            <span><i class="fa fa-share"></i>导出</span>
                        </div>
                    </a>
                </div>

            </div>
            <div style="clear:both"></div>
        </div>
        <div class="bDiv" style="height: auto;" id="ajax_return" data-url="{:U('admin/users/rest_data')}">
        </div>
    </div>
</div>
<script>
    function delAll_user(){
        layer.confirm('确认删除？', {btn: ['确定','取消'] }, function(){
                $.ajax({
                    type : 'get',
                    url : "{:U('admin/users/del_all')}",
                    data : {act:'del'},
                    dataType : 'json',
                    success : function(data){
                        layer.closeAll();
                        if(data.status == 1){
                            layer.msg('操作成功', {icon: 1},function(){
                                location.reload();
                            });
                        }else{
                            layer.msg(data.msg, {icon: 2,time: 2000});
                        }
                    }
                })
            }, function(index){
                layer.close(index);
                return false;// 取消
            }
        );
    }

    function publicHandleAll(type){
        var ids = '';
        $('#flexigrid .trSelected').each(function(i,o){
            ids += $(o).data('id')+',';
        });
        if(ids == ''){
            layer.msg('至少选择一项', {icon: 2, time: 2000});
            return false;
        }
        publicHandle(ids,type); //调用删除函数
    }
    /**
     * 公共操作（删，改）
     * @param type
     * @returns {boolean}
     */
    function publicHandle(ids,handle_type){
        layer.confirm('确认当前操作？', {
                btn: ['确定', '取消'] //按钮
            }, function () {
                // 确定
                $.ajax({
                    url: $('#ajax_return').data('url'),
                    type:'post',
                    data:{ids:ids,type:handle_type},
                    dataType:'JSON',
                    success: function (data) {
                        layer.closeAll();
                        if (data.status == 1){
                            layer.msg(data.msg, {icon: 1, time: 2000},function(){
                                window.location.reload();
                            });
                        }else{
                            layer.msg(data.msg, {icon: 5, time: 2000});
                        }
                    }
                });
            }, function (index) {
                layer.close(index);
            }
        );
    }

    function exportUser() {
        $('input[name="user_ids"]').val('');
        $('#search-form2').attr('action',"{:U('Users/export_user')}")
        var selected_ids = '';
        $('.trSelected' , '#flexigrid').each(function(i){
            selected_ids += $(this).data('id')+',';
        });
        if(selected_ids != ''){
            $('input[name="user_ids"]').val(selected_ids.substring(0,selected_ids.length-1));
        }
        $('#search-form2').submit();
    }

    $(document).ready(function(){
        // 点击刷新数据
        var ssort = 'sdesc';
        var on_sclick = 0;
        $('.hDivBox > table>thead>tr>th').hover(
            function () {
                if(typeof($(this).attr('abbr')) == "undefined"){
                    return false;
                }
                $(this).addClass('thOver');
                if($(this).hasClass('sorted')){
                    if(ssort == 'sdesc'){
                        $(this).find('div').removeClass('sdesc');
                        $(this).find('div').addClass('sasc');
                    }else{
                        $(this).find('div').removeClass('sasc');
                        $(this).find('div').addClass('sdesc');
                    }
                }else{
                    $(this).find('div').addClass(ssort);
                }
            }, function () {
                if(typeof($(this).attr('abbr')) == "undefined"){
                    return false;
                }
                if(on_sclick == 0){
                    if($(this).hasClass('sorted')){
                        if(ssort == 'sdesc'){
                            $(this).find('div').removeClass('sasc');
                            $(this).find('div').addClass('sdesc');
                        }else{
                            $(this).find('div').removeClass('sdesc');
                            $(this).find('div').addClass('sasc');
                        }
                    }else{
                        $(this).find('div').removeClass(ssort);
                    }
                }
                $(this).removeClass("thOver");
                on_sclick = 0;
            }
        );
        $('.hDivBox > table>thead>tr>th').click(function(){
            if(typeof($(this).attr('abbr')) == "undefined"){
                return false;
            }
            if($(this).hasClass('sorted')){
                $(this).find('div').removeClass(ssort);
                if(ssort == 'sdesc'){
                    ssort = 'sasc';
                }else{
                    ssort = 'sdesc';
                }
                $(this).find('div').addClass(ssort);
                on_sclick = 1;
            }else{
                $('.hDivBox > table>thead>tr>th').removeClass('sorted');
                $('.hDivBox > table>thead>tr>th').find('div').removeClass(ssort);
                $(this).addClass('sorted');
                $(this).find('div').addClass(ssort);
                var hDivBox_th_index = $(this).index();
                var flexigrid_tr =   $('#flexigrid > table>tbody>tr')
                flexigrid_tr.each(function(){
                    $(this).find('td').removeClass('sorted');
                    $(this).children('td').eq(hDivBox_th_index).addClass('sorted');
                });
            }
            sort($(this).attr('abbr'));
        });

        $('.fa-refresh').click(function(){
            location.href = location.href;
        });
        ajax_get_table('search-form2',1);

    });
    //选中全部
    $('.hDivBox .sign').click(function(){
        var sign = $('#flexigrid > table>tbody>tr');
        if($(this).parent().hasClass('trSelected')){
            sign.each(function(){
                $(this).removeClass('trSelected');
            });
            $(this).parent().removeClass('trSelected');
        }else{
            sign.each(function(){
                $(this).addClass('trSelected');
            });
            $(this).parent().addClass('trSelected');
        }
    })

    // ajax 抓取页面
    function ajax_get_table(tab,page){
        var search_key = $.trim($('#search_key').val());
        if(search_key.length > 0){
            $('#keywords').val(search_key);
        }
        cur_page = page; //当前页面 保存为全局变量
        $.ajax({
            type : "POST",
            url:"/index.php/Admin/users/wechat_ajax/p/"+page,//+tab,
            data : $('#'+tab).serialize(),// 你的formid
            success: function(data){
                $("#ajax_return").html('');
                $("#ajax_return").append(data);
            }
        });
    }

    // 点击排序
    function sort(field)
    {
        $("input[name='order_by']").val(field);
        var v = $("input[name='sort']").val() == 'desc' ? 'asc' : 'desc';
        $("input[name='sort']").val(v);
        ajax_get_table('search-form2',cur_page);
    }


</script>
</body>
</html>